package com.hujing;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatDemo {

    public static void main(String[] args) throws ParseException {
        // 将当前日期转成yyyy-MM-dd HH:mm:ss格式的字符串
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String format = sdf.format(date);
        System.out.println(format);

        // 将字符串2025-04-06 09:42:43解析成Date对象
        String str = "2025-04-06 09:42:43";
        Date date1 = sdf.parse(str);
        System.out.println(date1);
    }
}
